import Vue from 'vue'
import axios from 'axios'
import FastClick from 'fastclick'
import VueClipboard from 'vue-clipboard2'
import App from './App.vue'
import router from './router'
import store from './store/store' 
import { Toast,Indicator } from 'mint-ui';
import { getStore } from '@/assets/js/utils.js';
import './registerServiceWorker'
import './assets/css/global.css'
import 'mint-ui/lib/style.min.css'

FastClick.attach(document.body)
Vue.config.productionTip = false
Vue.prototype.$axios = axios
Vue.prototype.$Toast = Toast
Vue.use(VueClipboard)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

// 权限访问并验证
router.beforeEach((to, from, next) => {
  let url = window.location.href;
  if (to.path == '/wxLogin' || to.path == '/login') { //|| to.path == '/home' || to.path == '/wxLogin' || to.path == '/activityDetail' || to.path == '/find'|| to.path == '/my'|| to.path == '/hx' || to.path == '/login'
    next()
  } else {
    // 验证是否登录
    // let token = getStore('token');
    let userId = getStore('userId');
    if (userId) {
      Indicator.close();
      next()
    } else {
      Toast('你尚未登录');
      if(url.indexOf('/hx') != -1 || url.indexOf('/hxrecords') != -1){
        router.push('/login');
      }else{
        router.push('/wxLogin');
      }
    }
  }
})

// !function(){
//   var ua = navigator.userAgent.toLowerCase();
//   var isWeixin = ua.indexOf('micromessenger') != -1;
//   if (!isWeixin) {
//     if(window.location.href.indexOf("wxLogin") == -1){
//       router.push('/wxLogin');
//     }
//   }
// }()